//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics;
using System.Windows;

namespace OpenLS.UI.Interop
{
    internal class XpWindowMessageProcessor : WindowMessageProcessor
    {
        public XpWindowMessageProcessor(RibbonWindow w)
            : base(w)
        {
        }

        internal override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch ((WindowsMessages) msg)
            {
                case WindowsMessages.ThemeChanged:
                    _owner.IsGlass = NativeMethods.IsCompositionEnabled();
                    break;
                case WindowsMessages.GetMinMaxInfo:
                    return OnGetMinMaxInfo(hwnd, msg, wParam, lParam, ref handled);
                case WindowsMessages.NcHitTest:
                    return (IntPtr)(int)onNcHitTest(hwnd, msg, wParam, lParam, ref handled);
                    break;

            }
            return IntPtr.Zero;
        }

        private HitTest onNcHitTest(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            handled = false;
            var pt = new NativeMethods.POINT((int)lParam);
            {
                Point pt2 = pt.ToPoint();
                pt2 = _owner.PointFromScreen(pt2);
                if (pt2.Y < SystemParameters.CaptionHeight)
                {
                    if (pt2.X < SystemParameters.CaptionHeight)
                    {
                        handled = true;
                        return HitTest.SysMenu;
                    }
                }
            }
            return HitTest.NoWhere;

        }

    }
}